package com.example.lenovo.myapplication;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageButton;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageButton btn_wechat;
    private ImageButton btn_contact;
    private ImageButton btn_find;
    private ImageButton btn_we;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_new);
        btn_wechat = findViewById(R.id.imageButton1);
        
        btn_contact = findViewById(R.id.imageButton2);
        btn_find = findViewById(R.id.imageButton3);
        btn_we = findViewById(R.id.imageButton4);


        btn_wechat.setOnClickListener(this);
        btn_contact.setOnClickListener(this);
        btn_find.setOnClickListener(this);
        btn_we.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.imageButton1:
                selectTab(0);
            break;
            case R.id.imageButton2:
                selectTab(1);
                break;
            case R.id.imageButton3:
                selectTab(2);
                break;
            case R.id.imageButton4:
                selectTab(3);
                break;
                default:
                    break;
        }
    }
    public void selectTab(int index)
    {
        backButtonSelectTab();
        switch (index)
        {
            case 0:
                btn_wechat.setImageResource(R.drawable.tab_weixin_pressed);
                break;
            case 1:
                btn_contact.setImageResource(R.drawable.tab_address_pressed);
                break;
            case 2:
                btn_find.setImageResource(R.drawable.tab_find_frd_pressed);
                break;
            case 3:
                btn_we.setImageResource(R.drawable.tab_settings_pressed);
                break;

        }
    }

    private void backButtonSelectTab() {
        btn_wechat.setImageResource(R.drawable.tab_weixin_normal);

        btn_contact.setImageResource(R.drawable.tab_address_normal);

        btn_find.setImageResource(R.drawable.tab_find_frd_normal);

        btn_we.setImageResource(R.drawable.tab_settings_normal);

    }


}
